package Classic150;

public class 寻找旋转排序数组中的最小值 {
    /*
        理解为什么不是left <= right，并且为什么right = mid，left = mid + 1
     */
    public int findMin(int[] nums) {
        if (nums[0] < nums[nums.length - 1]) return nums[0];
        int left = 0, right = nums.length - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] < nums[0]) right = mid;
            else left = mid + 1;
        }
        return nums[left];
    }
}
